package cn.crex1.xiaomi.dao;

import java.util.List;

import cn.crex1.xiaomi.core.orm.annotion.Query;
import cn.crex1.xiaomi.core.orm.annotion.ResultType;
import cn.crex1.xiaomi.pojo.Category;
import cn.crex1.xiaomi.pojo.Product;
import cn.crex1.xiaomi.pojo.SAttribute;
import cn.crex1.xiaomi.pojo.Specification;
import cn.crex1.xiaomi.vo.CategoryVO;
import cn.crex1.xiaomi.vo.ProductVO;


public interface ProductDao {
	 @Query(sql = "SELECT os_product.name,os_product.show_price,os_product.introduce,os_product.pic_img,os_product.page_description,os_specification.name,os_specification_attribute.name FROM os_product LEFT JOIN os_product_category ON os_product.product_id=os_product_category.product_id LEFT JOIN os_specification ON os_product_category.category_id=os_specification.category_id LEFT JOIN os_specification_attribute ON os_specification.specification_id=os_specification_attribute.specification_id WHERE os_product.product_number=?;")
	 @ResultType(value="List")
	 List<Product> selectOsproductByDetails(Product product,SAttribute sAttribute,Specification specification);
	 
	@Query(sql = "insert into os_product(product_id,product_number,name,show_price,introduce,pic_img,create_time,update_time,page_title,page_description,remarks)values(?,?,?,?,?,?,?,?,?,?,?)")
	@ResultType(value = "int")
	int insertAllOsproduct(Product product);

	@Query(sql = "delete from os_product where product_id=?")
	@ResultType(value = "int")
	int deleteOsproductByProductid(Product product);

	@Query(sql = "update os_product set name=?,show_price=? where product_id=?")
	@ResultType(value = "int")
	int updateOsproductByShowpriceAndName(Product product);

	// 查询所有产品
	@Query(sql = "select product_id,product_number,name,show_price,introduce,pic_img,create_time,update_time,page_title,page_description,remarks from os_product")
	@ResultType(value = "List")
	List<Product> selectAllProduct(Product product);

	// 根据分类type查询分类
	@Query(sql = "select category_id,name,type,page_title from os_category where type=?")
	@ResultType("List")
	List<Category> selectAllProductcategory(Category category);

	// 分类查询小米手机
	@Query(sql = "select os_product.product_number,os_product.name,os_product.show_price,os_product.introduce,os_product.pic_img from"
			+ " os_category left join os_product_category on os_category.category_id=os_product_category.category_id "
			+ "left join os_product on os_product_category.product_id=os_product.product_id where  os_category.category_id=?")
	@ResultType(value = "List") // 定义返回值
	List<ProductVO> selectOProductByOCategoryId(ProductVO oProductVO);
	
	@Query(sql = "select oc.category_id,op.product_number,op.name,op.show_price,op.introduce,op.pic_img from os_category oc left join os_product_category opc on oc.category_id=opc.category_id left join os_product op on opc.product_id=op.product_id")
	@ResultType(value = "List") // 定义返回值
	List<ProductVO> selectAllCategoryProduct(ProductVO productVO);
}
